Skip to content

feat(mcp): --output-max-size with post-response disk eviction#41031

Merged
Skn0tt merged 4 commits into
microsoft:mainfrom
Skn0tt:feat-output-max-size-disk
May 29, 2026
Merged

feat(mcp): --output-max-size with post-response disk eviction#41031
Skn0tt merged 4 commits into
microsoft:mainfrom
Skn0tt:feat-output-max-size-disk

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented May 28, 2026

Alternative to #41021 implementing @pavelfeldman's suggestion: examine the response for new output-folder entries and remove oldest entries on disk, instead of intercepting at the write layer with OutputFile/OutputDir.

Approach

After Response.serialize() builds its sections, _enforceOutputBudget() recursively lists the output directory, sorts by mtime ascending, and unlinks oldest files until total <= outputMaxSize. Files written by the current Response are tracked in _writtenFiles and never evicted, so artifacts the response references stay readable.

Trade-offs vs #41021

  • +73 / -0 lines vs +391 / -44. No new types, no evictable plumbing.
  • Trace and sessionLog need no special-casing — their mtime bumps keep them young, naturally last to evict.
  • Sees externally-written files (downloads, trace bundles); they count against the budget and evict by age.
  • Self-healing on external filesystem changes.
  • Cap can briefly exceed during a single tool call that writes a large artifact; feat(mcp): add --output-max-size for output dir eviction #41021 pre-evicts so the cap is a hard ceiling.
  • Weaker pin guarantee for session.md and tracing — recency-based instead of flag-based.

…aft)

Alternative to microsoft#41021 implementing Pavel's suggestion: instead of
intercepting writes in code with an OutputFile/OutputDir layer, let
tools write whatever and prune the outputDir from disk after each
tool call.

After Response.serialize() builds its sections, _enforceOutputBudget
recursively lists outputDir, sorts by mtime ascending, and unlinks
oldest files until total <= outputMaxSize. Files written by the
current Response are tracked in _writtenFiles and never evicted, so
artifacts referenced in the response stay readable.

Config: same outputMaxSize field, --output-max-size CLI flag, and
PLAYWRIGHT_MCP_OUTPUT_MAX_SIZE env var as microsoft#41021.

Trade-offs vs microsoft#41021:
- ~74 lines added vs ~390; no new types or evictable plumbing.
- Trace/sessionLog need no special-casing — their mtime bumps keep
  them young, naturally last to evict.
- Sees externally-written files (downloads, trace bundles) — they
  count against the budget and evict by age.
- Self-healing on external fs changes.
- Cap can briefly exceed during a single tool call that writes a
  large artifact; microsoft#41021 pre-evicts so the cap is hard.
- Weaker pin guarantee for session.md (recency-based, not flag-based).
@Skn0tt Skn0tt changed the title feat(mcp): --output-max-size with post-response disk eviction (draft) feat(mcp): --output-max-size with post-response disk eviction May 28, 2026
@Skn0tt Skn0tt marked this pull request as ready for review May 28, 2026 07:18
@github-actions

This comment has been minimized.

Comment on lines 367 to +368

async function listFilesRecursive(dir: string): Promise<{ path: string, size: number, mtimeMs: number }[]> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we are already assuming Node 20 for MCP in other places, so can be shorter:

async function listFilesRecursive(dir: string) {
const entries = await fs.promises.readdir(dir, { recursive: true, withFileTypes: true });
const files = entries.filter(e => e.isFile());
return Promise.all(files.map(async e => {
const full = path.join(e.parentPath, e.name);
const { size, mtimeMs } = await fs.promises.stat(full);
return { path: full, size, mtimeMs };
}));
}

@github-actions

This comment has been minimized.

Screenshot sizes vary by browser (webkit produced ~21KB for hello-world,
exceeding the 10KB cap by itself), making the byte assertion flaky. Use
1KB downloads with deterministic sizes instead.
@Skn0tt Skn0tt merged commit 525f375 into microsoft:main May 29, 2026
17 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

7233 passed, 1113 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants